<?php
/**
* @package   auto_occasion
* @subpackage parution
* @author    your name
* @copyright 2011 your name
* @link      http://www.yourwebsite.undefined
* @license    All rights reserved
*/

class BoParutionCtrl extends jController {
	public $pluginParams = array(
                                    '*'=>array('auth.required'=>true,
                                    'jacl2.right'=>'admin.compte.gerer'
                                    )
                            );
    /**
    * Liste des parutions
    */
    function index() {

        //jClasses::inc("parution~parutionSrv");
        jClasses::inc("commun~common");

        $iParutionId                  = $this->intParam('id', '');
	
        $toParams['parutionNumero']    = common::liste('ao_parution');
        $toParams['parutionDetail']    = ($iParutionId) ? common::chargeParId($iParutionId, 'ao_parution') : common::init('ao_parution') ;

        $rep = $this->getResponse('html');
  		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jquery.validation.js');		$rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jconfirmaction.jquery.js');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jconfirmaction.jquery.ask.js');


	    $rep->addCSSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/css/jquery-ui.css');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jquery-ui.min.js');



		$rep->menusActifs = adminHtmlResponse::MENU_PARUTION ;

        $rep->body->assign($toParams) ;

        $rep->bodyTpl = 'parution~BoParutionEdit';
        return $rep;
    }

    /**
    * Sauvegarder un parution
    */
    function sauvegarder() {
        $rep = $this->getResponse('redirect');
        
        jClasses::inc('parution~parutionSrv');
        jClasses::inc('commun~communSrv');

        $parution               = new stdClass();
        $parution->parution_num         = $this->intParam('parution_num', 0);
        $parution->parution_date        = communSrv::toDateSql($this->stringParam('parution_date', ''));
        $parution->parution_bouclage    = communSrv::toDateSql($this->stringParam('parution_bouclage', ''));
        $parution->parution_limite      = communSrv::toDateSql($this->stringParam('parution_limite', ''));
		$parution->parution_relance     = communSrv::toDateSql($this->stringParam('parution_relance', ''));
		$parution->parution_suppr       = communSrv::toDateSql($this->stringParam('parution_suppression', ''));
		$parution->parution_id          = $this->intParam('id', 0);


        if ($parution->parution_id) {
            parutionSrv::modifier($parution);
        } else {
            parutionSrv::ajouter($parution);
        }
        
        $rep->action = 'parution~BoParution:index';

        return $rep;
    }

	    /**
    * Supprime une parution
    */
    function supprimer() {
        $rep = $this->getResponse('redirect');
        jClasses::inc('commun~common');

        $id = $this->stringParam('id');
        common::supprimer($id, 'ao_parution');

        $rep->action = 'parution~BoParution:index';

        return $rep;
    }
}

